/* eslint-disable react/jsx-key */
import React, { useState, useRef } from 'react';
import { Tooltip, message } from 'antd';
import InitForm from '@/components/InitForm';
import { user } from '@/services/basic';
import { connect } from 'umi';

function Accounting(props) {
  let defaultFields = {
    company_ids: {
      value: null,
      type: 'checktable',
      title: '代账公司',
      name: ['company_ids'],
      columns: [
        {
          title: '业务编号',
          dataIndex: 'code',
          key: 'code',
        },
        {
          title: '公司名称',
          width: 260,
          dataIndex: 'name',
          key: 'name',
          copyable: true,
        },
        {
          title: '月收费',
          dataIndex: 'unit_price',
          key: 'unit_price',
          search: false,
        },
        {
          title: '公司法人',
          dataIndex: 'legal_person',
          key: 'legal_person',
          search: false,
        },
        {
          title: '联系人',
          dataIndex: 'customer_name',
          key: 'customer_name',
          ellipsis: true,
          search: false,
        },
        {
          title: '联系人手机号',
          width: 120,
          dataIndex: 'customer_phone',
          key: 'customer_phone',
          search: false,
          render: (_, row) => (
            <Tooltip title={row.customer_phone}>
              <a href={`tel:${row.customer_phone}`} className="oneline">
                {row.customer_phone}
              </a>
            </Tooltip>
          ),
        },
        {
          title: '区域名称',
          dataIndex: 'area_name',
          key: 'area_name',
          search: false,
        },
        {
          title: '记账会计',
          dataIndex: 'account_user_name',
          key: 'account_user_name',
          //   valueType: 'select',
          //   options: {
          //     database: user,
          //     params: {
          //       is_all: 1,
          //     },
          //   },
        },
        {
          title: '公司类型',
          dataIndex: 'classify_name',
          key: 'classify_name',
          search: false,
        },
      ],
      rowKey: 'id',
      rowName: 'name',
      required: true,
      path: '/wbn-api/company',
      extraparams: {
        type: -1,
        account_user_id: props.user.currentUser.id,
        status: 'completed',
        service_type: 'account',
      },
      col: { span: 24 },
    },
    account_user_id: {
      value: null,
      type: 'select',
      title: '转至会计',
      name: ['account_user_id'],
      required: true,
      options: {
        database: user,
        params: { is_all: 1 },
      },
      col: { span: 24 },
    },
  };
  const [fields, cf] = useState(defaultFields);
  const [reload, setreload] = useState(true);

  let saveData = (values) => {
    let { dispatch } = props;
    dispatch({
      type: 'business/batch_change_account',
      payload: values,
    }).then((res) => {
      if (res.code == 0) {
        setreload(false);
        setTimeout(() => {
          setreload(true);
        }, 10);
        message.success('操作成功');
      }
    });
  };

  return (
    <div className="pgcontainer">
      {reload && (
        <InitForm
          fields={fields}
          submitData={(values) => {
            saveData(values);
          }}
          onChange={() => {
            //联动操作
          }}
          submitting={props.loading.effects['business/addcompany']}
        />
      )}
    </div>
  );
}

export default connect(({ business, loading, user }) => ({
  business,
  loading,
  user,
}))(Accounting);
